package com.project.gjbus.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.project.gjbus.dto.ParamDto;
import com.project.gjbus.entity.Jinchuzhan;
import com.project.gjbus.mapper.JinchuzhanMapper;
import com.project.gjbus.service.JinchuzhanService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class JinchuzhanServiceImpl implements JinchuzhanService {

    @Resource
    private JinchuzhanMapper jinchuzhanMapper;

    @Override
    @DS("master")
    public Integer getCount(ParamDto paramDto) {
        return jinchuzhanMapper.getCount(paramDto);
    }

    @Override
    @DS("master")
    public Integer getCountByFlag() {
        return jinchuzhanMapper.getCountByFlag();
    }

    @Override
    @DS("master")
    public List<Jinchuzhan> getList(ParamDto paramDto) {
        return jinchuzhanMapper.getList(paramDto);
    }

    @Override
    @DS("master")
    public List<Jinchuzhan> getListByFlag(ParamDto paramDto) {
        return jinchuzhanMapper.getListByFlag(paramDto);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("readbase")
    public void saveList(List<Jinchuzhan> list) {
        for (Jinchuzhan entity : list) {
            jinchuzhanMapper.insertSelective(entity);
        }
    }

    @Override
    @DS("readbase")
    public Integer getReadBaseCount(ParamDto paramDto) {
        return jinchuzhanMapper.getCountReadbase(paramDto);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("master")
    public void deleteById(Long id) {
        ParamDto paramDto = new ParamDto();
        paramDto.setId(id);
        jinchuzhanMapper.deleteById(paramDto);
    }
}
